﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/topLess.jsp"%>
<form name="myForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${id}" />
<table>
		<tbody>
			<tr class="tab_grey">
				<td>
		报表制度:
		<select id="statistics" name="statistics" onchange="getVersion($('#statistics').val());"  class="tab_textbut" >
			<option value="">请选择..</option>
			<c:forEach var="sys" items="${sysCodeList}">					
                 	<option value="${sys.code}">${sys.codeName}</option>
            </c:forEach>
		</select>
		
		<span class="tab_text">报表版本:</span>
		<select id="vs" name="vs" onchange="getRep($('#statistics').val(),$('#vs').val());"  class="tab_textbut_200" >
			<option value="">请选择..</option>
			<c:forEach var="vs" items="${vsList}">
                   <option value="${vs.id}">${vs.versionSystem}</option>
               </c:forEach>
		</select>
				
		<span class="tab_text">填报报表:</span>
		<select id="typeId" name="typeId" class="tab_textbut_300" >
			<option value="">请选择..</option>
        </select>
		
	<br/><br/>
			指标名称：
				<input type="text" value="${param['indicatorName']}" id="indicatorName" name="indicatorName" maxlength="20" class="tab_textbut" >&nbsp;&nbsp;
			<input type="button" value="查询指标" onclick="indicatorQuery()" class="tab_but" />
			<input type="button" value="保存" class="tab_but" onclick="save();"/>
			<br> <br>
			<div style="width: 250px; float: left">
				备选列表：<br />
			<select id="indicatorLeftSel" class="tab_textbut_300"
						style="width: 250px; height: 300px" size="20" ondblclick="indicatorSelectToRight()" multiple="multiple">
				
			</select>
	</div>
				<div style="width: 98px; float: left; padding:150px 20px 20px 25px; text-align: left">
			<input type="button" value="添加" class="tab_but" onclick="indicatorSelectToRight();"/><br/><br/>
			<input type="button" value="删除" class="tab_but" onclick="indicatorDelSel();"/>
			</div>
				<div style="width: 250px; float: left">
					选中列表：<br />
			<select id="indicatorRightSel" name="indicatorRightSel" class="tab_textbut_300" style="width: 250px; height: 300px"
						size="20" ondblclick="indicatorDelSel()" multiple="multiple">
			<c:forEach var="indicator" items="${industryIndicators}">
		                   <option value="${indicator.indicatorId}">${indicator.indicatorName}</option>
	            </c:forEach>
			</select>
		</div>
			</td>
			</tr>
		</tbody>
</table>
	
</form>

<script>

//根据报表类型查询报表版本信息和表号信息
function getVersion(typeId){		
	var versionObj = $("#vs");
	var reportTypeObj = $("#typeId");
	var reportNoObj = $("#reportNo");		
	
	initSelect(versionObj);	//初始化select
	initSelect(reportTypeObj);	//初始化select
	initSelect(reportNoObj);	//初始化select
	
	if (typeId!=""){
		//查询报表报表信息
		var v_url = "${baseURL}/company/report/queryReportVersion/" + typeId;
		$.ajax({			
			url:v_url,
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data.operationResult, function(i, item){						
					var selected = "";						
					if ("${param['versionId']}" == item.id){
						selected = "selected";
					}						
					versionObj.append("<option value='" + item.id + "' " + selected + " >" + item.versionSystem + "</option>");
				});
				
				versionObj.change();
			}
		});

		//查询报表表号信息
		var no_url = "${baseURL}/company/report/queryTypeNo/" + typeId;
		$.ajax({			
			url:no_url,
			type:"post",
			dataType:"json",
			success:function(data){
				$.each(data, function(i, item){
					var selected = "";						
					if ("${requestScope.typeNo}" == item.typeNo){
						selected = "selected";
					}	
					reportNoObj.append("<option value='" + item.typeNo + "' " + selected + " >" + item.typeNo + "</option>");
				});
			}
		});
		
	}
}

//根据报表类型查和报表版本查询所有的报表信息
function getRep(typeId, versionId){		
	var reportTypeObj = $("#typeId");	
	initSelect(reportTypeObj);	//初始化select
	if (typeId!=""&&versionId!=""){
		var url = "${baseURL}/company/report/queryReportTypesByParam/" + versionId + "/" + typeId;
		$.ajax({			
			url:url,
			type:"post",
			dataType:"json",
			success:function(data){					
				$.each(data, function(i, item){						
					var selected = "";						
					if ("${param['reportTypeId']}" == item.id){
						selected = "selected";
					}						
					reportTypeObj.append("<option value='" + item.id + "' " + selected + ">" + item.typeName + "</option>");
				});
			}
		});
	}
}	

//初始化select
function initSelect(s_obj){		
	s_obj.empty();		
	s_obj.append("<option value=''>请选择..</option>");
	
}
//查找指标
function indicatorQuery(){
	var sysId = $('#statistics').val(); //制度id
	var vsId = $("#vs").val(); //版本id
	var typeId=$("#typeId").val();//报表ID
	var name=$("#indicatorName").val();//名称
	var url = "${ctx}/indicator/queryList";
	var data = "sysId="+sysId+"&vsId="+vsId+"&typeId="+typeId+"&name="+name;
   	$.ajax({
   		url:url,
   		type:'post',
   		dataType:'json',
   		data:data, 
   		success:function(data){
   			$("#indicatorLeftSel").empty();
   			//var result = eval('(' + data + ')');
   			//if (!$.isEmptyObject(result)) {
   				$.each(data, function(i, item) {
   					$("#indicatorLeftSel").append(
   							"<option value='" + item.id + "'>" + item.name+ "</option>");
   				});
   			//}
   		}
   	});
	
}

function save() {
	var indicator = "";
	var options = $("#indicatorRightSel option");
   	if (options.length!=0){
	   	$.each(options, function(i, option){
	   		if (i > 0)
	   			indicator += ",";
	   		indicator += option.value;
	   	});
   	}
   	var params = "id=" + $("#id").val()+"&indicators="+indicator;
   	var url = "manageIndicator";
   	$.ajax({
   		url: url,
		type: 'post',
		dataType: 'json',
		data : params,
		success: function(data){
			if (data.ok){
				alert(data.message);
					closeWin();
			}else{
				alert('操作异常:'+data.message);
			}
		}
	});
}



//从左边列表选择到右边列表
function indicatorSelectToRight() {

	var options = $("#indicatorLeftSel option:selected");
	if ($(options).val() != "") {
		$.each(options, function(i, option) {
			if ($("#indicatorRightSel option[value='" + $(option).val() + "']").val() == undefined) {
				$("#indicatorRightSel").append("<option value='" + $(option).val() + "'>"+ $(option).text() + "</option>");
			}
		});
		options.remove();
	}
}

function indicatorDelSel() {
	var options = $("#indicatorRightSel option:selected");
	if ($(options).val() != "") {
		$.each(options, function(i, option) {
			if ($("#indicatorLeftSel option[value='" + $(option).val() + "']").val() == undefined) {
				$("#indicatorLeftSel").append("<option value='" + $(option).val() + "'>" + $(option).text() + "</option>");
			}
		});
		$("#indicatorLeftSel option:selected").remove();
	}
	options.remove();
}

</script>
<%@ include file="/static/include/bottom.jsp"%>